package bat.ke.qq.com;

import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;

/**
 * 使用内嵌 tomcat
 */
@Slf4j
public class App {

    private static int PORT = 8080;

    public static void main(String[] args) throws LifecycleException {
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(PORT);
        // 添加应用
        tomcat.addContext("/", System.getProperty("user.dir"));
        Wrapper wrapper = tomcat.addServlet(
                "/", "helloServlet", new HelloServlet());
        wrapper.addMapping("/hello");
        tomcat.start();
        log.info("start tomcat success, port: {}", PORT);
        // 阻塞tomcat
        tomcat.getServer().await();
    }

}
